<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
FlyUI Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="bdgp-service.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>bdgp-service.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		This script defines utilities for interacting with data from www.fly-ted.org.
 <BR/><BR/><B>Version: </B>$Revision:538 $ on $Date: 2008-08-27 09:08:41 +0100 (Wed, 27 Aug 2008) $ by $Author: aliman $
 <BR/><BR/><B>Requires:</B><UL>- YAHOO.util.Connect<BR/>- flyui.bdgp.GeneNameMappings
 TODO license terms</UL><B>Author:</B> <a href="http://purl.org/net/aliman">Alistair Miles</a>, Graham Klyne, Jun Zhao
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/bdgp/ImagePool.html">flyui.bdgp.ImagePool</a></b></td>
    <td>A pool of image objects.</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/bdgp/Service.html">flyui.bdgp.Service</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/bdgp/StagePool.html">flyui.bdgp.StagePool</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * <span class="attrib">@fileoverview</span>
 * This script defines utilities for interacting with data from www.fly-ted.org.
 * <span class="attrib">@author</span> &lt;a href="http://purl.org/net/aliman"&gt;Alistair Miles&lt;/a&gt;, Graham Klyne, Jun Zhao
 * <span class="attrib">@version</span> $Revision:538 $ on $Date: 2008-08-27 09:08:41 +0100 (Wed, 27 Aug 2008) $ by $Author: aliman $
 * <span class="attrib">@requires</span> YAHOO.util.Connect
 * <span class="attrib">@requires</span> flyui.bdgp.GeneNameMappings
 * TODO license terms
 */</span>

<span class="comment">// create a namespace if not already defined</span>
flyui.namespace(<span class="literal">"flyui.bdgp"</span>);

<span class="comment">/**
 * TODO doc me
 */</span>
flyui.bdgp.Service = <span class="reserved">function</span> (endpointURL) {
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._endpoint = endpointURL;
}


<span class="comment">// extend</span>
flyui.bdgp.Service.<span class="reserved">prototype</span> = new flyui.sparql.Service();


flyui.bdgp.Service.<span class="reserved">prototype</span>.findImagesByAnyGeneLabel = <span class="reserved">function</span>( geneLabel, success, failure) {
    var _context = <span class="literal">"flyui.bdgp.Service.prototype.findImagesByAnyGeneLabel"</span>;
	try {
		flyui.info(<span class="literal">"geneLabel: "</span>+geneLabel, _context);
		var successChain = flyui.chain(flyui.bdgp.Service.responseToImages, success);
		var query = flyui.bdgp.Service._buildQueryForFindImagesByAnyGeneLabel(geneLabel);		
		<span class="reserved">this</span>.query(query, successChain, failure);
	} catch (error) {
        	throw new flyui.UnexpectedException(_context, error);
    }	
}


<span class="comment">/**
 * Convert an HTTP response to an array of Images.
 * <span class="attrib">@param</span> {Object} response a YUI success case response object
 * <span class="attrib">@type</span> Array&lt;flyui.bdgp.Image&gt;
 * <span class="attrib">@static</span>
 */</span>
flyui.bdgp.Service.responseToImages = <span class="reserved">function</span>( response ) {
    var _context = <span class="literal">"flyui.bdgp.Service.responseToImages"</span>;
    try {
        flyui.debug(<span class="literal">"response status: "</span>+response.status, _context);
        flyui.debug(<span class="literal">"response text: "</span>+response.responseText, _context);
        flyui.debug(<span class="literal">"try parsing response text as json"</span>, _context);
        var resultSet = YAHOO.lang.JSON.parse(response.responseText);
        flyui.debug(<span class="literal">"convert result set to an array of genes"</span>, _context);
        var images = flyui.bdgp.Stage.newInstancesFromSPARQLResults(resultSet);
        <span class="reserved">return</span> images;        
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name+<span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }
}


<span class="comment">/**
 * Build a SPARQL query to retrieve images by bdgp gene name.
 * <span class="attrib">@param</span> {String} anyName the gene name to search by
 * <span class="attrib">@return</span> a SPARQL query
 * <span class="attrib">@type</span> String
 * <span class="attrib">@private</span>
 * <span class="attrib">@static</span>
 */</span>
flyui.bdgp.Service._buildQueryForFindImagesByAnyGeneLabel = <span class="reserved">function</span>( geneLabel ) {

	try {
		var prefixes = 	<span class="literal">"PREFIX bdgp: &lt;http://purl.org/net/bdgp/schema/&gt;  "</span> +
						<span class="literal">"PREFIX owl: &lt;http://www.w3.org/2002/07/owl#&gt; "</span> +
						<span class="literal">"PREFIX skos: &lt;http://www.w3.org/2004/02/skos/core#&gt; "</span> +
						<span class="literal">"PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt; "</span> +
						<span class="literal">"PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; "</span> +		
						<span class="literal">"PREFIX : &lt;http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#&gt; "</span> +
						<span class="literal">"PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; "</span> +
						<span class="literal">"PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt; "</span>;					
	
	    var body = <span class="literal">"select distinct ?imagepath ?stage ?developmentStage ?expression where {"</span> +
	              <span class="literal">"?gp skos:altLabel '"</span> + geneLabel + <span class="literal">"'; rdf:type bdgp:GeneProduct ."</span> +
	              <span class="literal">"?association bdgp:geneProduct ?gp ; bdgp:associate ?evidence ; bdgp:term ?term."</span> +
	              <span class="literal">"?evidence bdgp:evidence ?img ."</span> +
	              <span class="literal">"?img rdf:type bdgp:Image ; bdgp:imagePath ?imagepath."</span> +
	              <span class="literal">"?img bdgp:imageToTerm ?stage."</span> +
	              <span class="literal">"?stage bdgp:name ?developmentStage."</span> +
	              <span class="literal">"?term bdgp:name ?expression ."</span> +
	              <span class="literal">"}"</span> + 
	              <span class="literal">"order by ?stage"</span>;
	              
							
		var query = prefixes + body;
	
		<span class="reserved">return</span> query;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.Service._buildQueryForFindImagesByAnyGeneLabel"</span>, error);
    }
};

flyui.bdgp.Stage = <span class="reserved">function</span> (){
	try {
		var that = <span class="reserved">this</span>;
		
		<span class="reserved">this</span>.stageName = null;
		
		<span class="reserved">this</span>.images = new Array();
		
		<span class="reserved">this</span>.stageURI = null;
		
		<span class="reserved">this</span>.addImage = <span class="reserved">function</span> (image){
			flyui.util.appendIfNotMember(that.images, image);
		};
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.Stage"</span>, error);
    }
};

<span class="comment">/**
 * TODO doc me
 */</span>
flyui.bdgp.Stage.newInstancesFromSPARQLResults = <span class="reserved">function</span>( resultSet ) {
	try {
	
		var stagePool = new flyui.bdgp.StagePool();
		var imagePool = new flyui.bdgp.ImagePool();
		var bindings = resultSet.results.bindings;
		
		<span class="reserved">for</span> (var i=0; i&lt;bindings.length; i++) {
			var binding = bindings[i];
			var stageURI = binding.stage.value;
			var stage = stagePool.get (stageURI);	
					
			<span class="reserved">if</span> (binding.developmentStage &amp;&amp; !stage.stageName) {
				stage.stageName = binding.developmentStage.value;
			}
			
			<span class="reserved">if</span> (binding.imagepath){
				var imageURI = binding.imagepath.value;
				var image = imagePool.get(imageURI);
				
				<span class="reserved">if</span> (!image.expressions){
					image.expressions = new Array();
				}
	
				<span class="reserved">if</span> (binding.expression) {
					var expression = binding.expression.value;
					<span class="reserved">if</span> (expression == <span class="literal">"stage1-3"</span> || expression == <span class="literal">"stage4-6"</span> || expression == <span class="literal">"stage7-8"</span> || expression == <span class="literal">"stage9-10"</span> || expression == <span class="literal">"stage11-12"</span> || expression == <span class="literal">"stage13-16"</span>){
						flyui.debug(<span class="literal">"test: "</span> + expression + <span class="literal">" is not an expression term"</span> );
					}<span class="reserved">else</span>{
						flyui.util.appendIfNotMember(image.expressions, expression);
					}
				}
				stage.addImage(image);
			}		
		}
		<span class="reserved">return</span> stagePool.toArray();
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.Stage.newInstancesFromSPARQLResults"</span>, error);
    }
};

<span class="comment">/**
 * Create a pool of image objects.
 * <span class="attrib">@class</span>
 * A pool of image objects.
 * <span class="attrib">@constructor</span>
 */</span>
 
flyui.bdgp.ImagePool = <span class="reserved">function</span>() {
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._pool = new Object();
};

flyui.bdgp.StagePool = <span class="reserved">function</span>() {
	<span class="reserved">this</span>._pool = new Array();
}

flyui.bdgp.StagePool.<span class="reserved">prototype</span>.get = <span class="reserved">function</span>( stageURI ) {
	try {
		var stage = <span class="reserved">this</span>._pool[stageURI];
		
		<span class="reserved">if</span> ( typeof stage == <span class="literal">"undefined"</span> || !stage ) {
			stage = new flyui.bdgp.Stage();
			stage.stageURI = stageURI;
			<span class="reserved">this</span>._pool[stageURI] = stage;	
		}
		
		<span class="reserved">return</span> stage;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.StagePool.prototype.get"</span>, error);
    }
};

flyui.bdgp.StagePool.<span class="reserved">prototype</span>.toArray = <span class="reserved">function</span>() {
	try {
		var array = new Array();	
		<span class="reserved">for</span> (var key in <span class="reserved">this</span>._pool) {
			array[array.length] = <span class="reserved">this</span>._pool[key];
		}
		<span class="reserved">return</span> array;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.StagePool.prototype.toArray"</span>, error);
    }
}

<span class="comment">/**
 * Get a image object from the pool, or create a new one if it doesn't exist.
 * <span class="attrib">@param</span> {String} imagepath 
 * <span class="attrib">@return</span> a flyui.bdgp.Image object
 */</span>
flyui.bdgp.ImagePool.<span class="reserved">prototype</span>.get = <span class="reserved">function</span>( imagepath ) {
	try {
		var image = <span class="reserved">this</span>._pool[imagepath];
		
		<span class="reserved">if</span> (!image ) {
			image = new Object();
			image.fullImageURL = <span class="literal">"http://www.fruitfly.org/insituimages/insitu_images/"</span> + imagepath;
			image.thumbnailURL = <span class="literal">"http://www.fruitfly.org/insituimages/insitu_images/thumbnails/"</span> + imagepath;
			<span class="reserved">this</span>._pool[imagepath] = image;	
		}
		
		<span class="reserved">return</span> image;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImagePool.prototype.get"</span>, error);
    }
};

flyui.bdgp.ImagePool.<span class="reserved">prototype</span>.toArray = <span class="reserved">function</span>() {
	try {
		var array = new Array();
		<span class="reserved">for</span> (var key in <span class="reserved">this</span>._pool) {
			array[array.length] = <span class="reserved">this</span>._pool[key];
		}
		<span class="reserved">return</span> array;
	}catch (error) {
        	throw new flyui.UnexpectedException(<span class="literal">"flyui.bdgp.ImagePool.prototype.toArray"</span>, error);
    }
}

</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Tue Dec  9 11:08:18 2008</div>
</body>
</html>
